<template>
	<view class="">
		<view class="bg1580E7 " :style="{paddingTop:shh+'px'}"></view>
		<view class="pt20 pb30 bg1580E7 ">
			<view class="con flex-ju-b">
				<image @click="tiai" mode="widthFix" class="width50 image" src="/static/push.png"></image>
				<view class=" colorfff">AI咨询</view>
				<view class="width50"></view>
			</view>
		</view>
		<view>
			<view v-if="isdata" class="flex-ju-c bold size40 mt10vh ">
				点左上角加号发起AI咨询
			</view>
		</view>
		
		<view  v-for="(item,index) in record" class="flex-ju-b border-tb8b8b8 pg30" :key="index">
			<view @click="navto('hitist?index='+item.id)" class="con flex1 flex-a-i flex ">
				<view>
					<image :src="user.avatar" class="wh110-110 ra110 mr15"></image>
				</view>
				<view>
					<view class="size30" style="max-width: 400rpx;">{{item.session_title}}</view>
					<view class="size22 colorB8B8B8 mt10 one">{{item.create_time}}</view>
				</view>
			</view>
			<view @click="deltr(item,index)" class="color006AE0 size24">删除</view>
		</view>
		
		<!-- <view>
			<view class="con flex-a-i flex mt30">
				<image src="/static/aaa.png" class="wh110-110 ra110 mr15"></image>
				<view>
					<view class="size30">豆包</view>
					<view class="size22 colorB8B8B8 mt10">新创想科技有限公司的年利润</view>
				</view>
			</view>
			<view class="border-tb8b8b8 mt30"></view>
		</view> -->
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isdata:false,
				user:{},
				record:[],
			}
		},
		onLoad() {
			
		},
		onShow() {
			
			this.user=uni.getStorageSync('user')
			this.http('ai/sessions').then(res=>{
				this.record = res.data.sessions
				if(this.record.length){
					this.isdata=false
				}else{
					this.isdata=true
				}
			}).catch(res=>{
				if(this.record.length){
					this.isdata=false
				}else{
					this.isdata=true
				}
			})
			
			// console.log(uni.getStorageSync('record'),"ppp")
			// if(uni.getStorageSync('record').length){
			// 	this.isdata=false
			// 	this.record=uni.getStorageSync('record')
			// }else{
			// 	this.isdata=true
			// }
		},
		methods: {
			deltr(item,index){
				uni.showModal({
					content:'确定删除吗？',
					success:  (res)=> {
						if (res.confirm) {
							this.http('ai/session/'+item.id,{
							},'delete').then(res=>{
								this.record.splice(index,1)
								uni.showToast({
									title:"删除成功",
									icon:"none"
								})
								if(this.record.length){
									this.isdata=false
								}else{
									this.isdata=true
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			tiai(){
				if(!uni.getStorageSync('token')){
					uni.showModal({
						content:'请先登录',
						success: (res) =>{
								if (res.confirm) {
									uni.reLaunch({
										url:"/pages/user/index"
									})
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
					})
					return
				}
				if(this.user.is_vip !=1){
					uni.showModal({
						content:'你还不是会员，是否开通？',
						success: (res) =>{
								if (res.confirm) {
									uni.navigateTo({
										url:"/pages/user/activate_vip"
									})
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
					})
					return
				}
				uni.navigateTo({
					url:"ai"
				})
			}
		}
	}
</script>

<style>
	page{
		background: #fff;
	}
.flex-a-i{
	align-items: center;
}
</style>
